<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="../../Templates/SubFolderTemplate.xhtml"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        
            <h:form prependId="false">
                <p:panel id="panel" header="View Raw Material Purchasing Order"> 
                    <p:ajaxStatus style="width:16px;height:16px;">   
                        <f:facet name="start">   
                            <p:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" /> 
                        </f:facet> 

                        <f:facet name="complete">   
                            <h:outputText value="" />   
                        </f:facet>   
                    </p:ajaxStatus>  
                    
                    <p:messages id="status"/>
                    
                    <p:fieldset legend="Material Purchasing Order List">
                        <p:dataTable var="materialOrder" value="#{viewMaterialOrder.materialOrders}"
                                     selection="#{viewMaterialOrder.selectedMaterialOrder}" id="orderTable"
                                     dynamic="true" paginator="true" rows="5" emptyMessage="No Material order"> 

                            <p:column selectionMode="single" />

                            <p:column sortBy="#{materialOrder.materialOrderId}" filterBy="#{materialOrder.materialOrderId}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Material Order ID" /> 
                                </f:facet> 
                                <h:outputText value="#{materialOrder.materialOrderId}" /> 
                            </p:column> 

                            <p:column sortBy="#{materialOrder.currentDate}" filterBy="#{materialOrder.currentDate}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Date" /> 
                                </f:facet> 
                                <h:outputText value="#{materialOrder.currentDate}" /> 
                            </p:column> 

                            <p:column sortBy="#{materialOrder.materialRequestTemp.materialRequest.materialRequestId}" filterBy="#{materialOrder.materialRequest.materialRequest.materialRequestId}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Request Id" /> 
                                </f:facet> 
                                <h:outputText value="#{materialOrder.materialRequestTemp.materialRequest.materialRequestId}" /> 
                            </p:column>              

                            <p:column sortBy="#{materialOrder.supplier.supplierName}" filterBy="#{materialOrder.supplier.supplierName}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="Supplier Name" /> 
                                </f:facet> 
                                <h:outputText value="#{materialOrder.supplier.supplierName}" /> 
                            </p:column>
                            
                            <p:column sortBy="#{materialOrder.materialOrderState}" filterBy="#{materialOrder.materialOrderState}"> 
                                <f:facet name="header"> 
                                    <h:outputText value="State" /> 
                                </f:facet> 
                                <h:outputText value="#{materialOrder.materialOrderState}" /> 
                            </p:column>

                            <f:facet name="footer">                        
                                <p:commandButton value="View" image="ui-icon ui-icon-search" update="display1 display2" onclick="MaterialOrderDialog.show()" />
                                <p:commandButton value="Sent Out" actionListener="#{viewMaterialOrder.sendMaterialOrder}" update="orderTable status"/>
                                <p:commandButton value="Materials Received" actionListener="#{viewMaterialOrder.receiveMaterials}" update="orderTable status"/>
                            </f:facet>            
                        </p:dataTable>
                    </p:fieldset>
  
                    <p:spacer height="20"/>
                    
                    
                    <p:dialog header="Material Purchasing Order Details" widgetVar="MaterialOrderDialog" width="600" height="400" resizable="true" 
                          showEffect="clip" hideEffect="fold">
                        <h:panelGrid id="display1" columns="2" cellpadding="4">
                            <h:outputText value="ID:"/>
                            <h:outputText value="#{viewMaterialOrder.selectedMaterialOrder.materialOrderId}"/>

                            <h:outputText value="Date:"/>
                            <h:outputText value="#{viewMaterialOrder.selectedMaterialOrder.currentDate}"/>

                            <h:outputText value="Supplier Name:"/>
                            <h:outputText value="#{viewMaterialOrder.selectedMaterialOrder.supplier.supplierName}"/>

                            <h:outputText value="Supplier Contact Number:"/>
                            <h:outputText value="#{viewMaterialOrder.selectedMaterialOrder.supplier.supplierContactNo}"/>

                            <h:outputText value="Supplier Eamil:"/>
                            <h:outputText value="#{viewMaterialOrder.selectedMaterialOrder.supplier.supplierEmail}"/>                    
                        </h:panelGrid>
                        
                        <p:dataTable var="materialLine" value="#{viewMaterialOrder.selectedMaterialOrder.materialLines}"
                                     dynamic="true" emptyMessage="No Raw Material Type" id="display2">
                            <p:column sortBy="#{materialLine.rawMaterial.materialType}">
                                <f:facet name="header">
                                    <h:outputText value="Raw Material Type"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.rawMaterial.materialType}"/>
                            </p:column>

                            <p:column sortBy="#{materialLine.rawMaterial.lotSize}" >
                                <f:facet name="header">
                                    <h:outputText value="Lot Size"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.rawMaterial.lotSize} "/>
                            </p:column>

                            <p:column sortBy="#{materialLine.lotQuantity}">
                                <f:facet name="header">
                                    <h:outputText value="Lot Quantity"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.lotQuantity}"/>
                            </p:column>
                            
                            <p:column>
                                <f:facet name="header">
                                    <h:outputText value="Total Quantity"/>
                                </f:facet>
                                <h:outputText value="#{materialLine.lotQuantity*materialLine.rawMaterial.lotSize}"/>
                            </p:column>

                            <f:facet name="footer">
                                <h:outputText value="Save as PDF"/>
                                <h:commandLink>  
                                    <p:graphicImage value="/images/pdf.png" />  
                                    <p:dataExporter type="pdf" target="display2" fileName="Purchasing_Order"/>  
                                </h:commandLink>

                                <p:commandButton value="Update" image="ui-icon ui-icon-close" onclick="materialOrderUpdateDialog.show()">
                                    <f:setPropertyActionListener value="#{materialOrder}" target="#{viewMaterialOrder.selectedMaterialOrder}"/>
                                </p:commandButton>

                            </f:facet>
                        </p:dataTable>
                        <p:messages id="status2"/>
                    </p:dialog>
                    
                    <p:confirmDialog message="Are you sure to edit the material order?"  
                                     showEffect="clip" hideEffect="fold" 
                                     header="Initiating edit process" severity="alert" widgetVar="materialOrderUpdateDialog">  
                        <p:commandButton value="Yes" update="status2" oncomplete="materialOrderUpdateDialog.hide()"  
                                         actionListener="#{viewMaterialOrder.updateMaterialOrder}" />  
                        <p:commandButton value="No" onclick="materialOrderUpdateDialog.hide()" type="button" />   
                    </p:confirmDialog>   
                    
                </p:panel>
            </h:form>
     
    </ui:define>
</ui:composition>
